import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:toolbox/manager/hive/hiveHelper.dart';
import 'package:toolbox/manager/net/networkHelper.dart';
import 'package:toolbox/manager/routeConfig.dart';

import 'common/strings.dart';
import 'manager/global.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  launchApp();
}

void launchApp() async {
  await HttpUtil.init();
  await HiveHelper.init();
  ///获取当前版本信息
  GlobalUtil.packageInfo = await PackageInfo.fromPlatform();
  GlobalUtil.getInstance().checkVersion();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: Strings.ciallo,
      locale: const Locale('zh', 'CN'), //设置默认语言
      fallbackLocale: const Locale("zh", "CN"), // 在配置错误的情况下,使用的语言
      localizationsDelegates: const [
        GlobalCupertinoLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('zh', 'CH'),
      ],
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        tabBarTheme: const TabBarTheme(dividerColor: Colors.transparent),
      ),
      getPages: RouteConfig.getPages,
      initialRoute: RouteConfig.homePage,
      builder: BotToastInit(),
      navigatorObservers: [BotToastNavigatorObserver()],
    );
  }
}
